package biblio.dao;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Properties;

public class ConnectionFactory {
	public Connection getConnection() throws SQLException, ClassNotFoundException, IOException
	{
		Connection cnx;
		Properties prop = new Properties();
		InputStream input = null;	
		input = new FileInputStream("infos.properties");
		prop.load(input);
		Class.forName(prop.getProperty("driver"));
		cnx= DriverManager.getConnection(prop.getProperty("url"),prop.getProperty("user"),prop.getProperty("pwd"));
		input.close();
		return cnx;
	}
	
	public Connection getConnection (String nomPilote, String URLBD, String authorizationID, String Password) throws SQLException, ClassNotFoundException
	{
		Connection cnx;
		Class.forName(nomPilote);
		cnx= DriverManager.getConnection(URLBD,authorizationID,Password);
		return cnx;
	}
	public Connection getConnectionSansAutoCommit (String nomPilote, String URLBD, String authorizationID, String Password) throws SQLException, ClassNotFoundException
	{
		Connection cnx;
		Class.forName(nomPilote);
		cnx= DriverManager.getConnection(URLBD,authorizationID,Password);
		cnx.setAutoCommit(false);
		return cnx;
	}
	
}
